#pragma once

#include "Log.hpp"
#include <iostream>
#include <string>

enum ErrorCode
{
    DevideZero,
    ModZero,
    Unknown,
    Normal
};

class Task
{
public:
    Task(int x, int y, char op)
        :a(x), b(y), op_(op) 
    {}

    void run()
    {
        switch(op_)
        {
            case '+':
                answer = a + b;
                break;
            case '-':
                answer = a - b;
                break;
            case '*':
                answer = a * b;
                break;
            case '/':
                if (b != 0) answer = a / b;
                else exitcode = DevideZero;
                break;
            case '%':
                if (b != 0) answer = a % b;
                else exitcode = ModZero;
                break;
            default:
                lg(Error, "Using correct operation: + - * / %");
                exitcode = Unknown;
                break;
        }
        
    }

    std::string GetTask()
    {
        std::string ret;
        ret += "Task: ";
        ret += std::to_string(a);
        ret += " ";
        ret += op_;
        ret += " ";
        ret += std::to_string(b);
        ret += " ";
        ret += "= ?";

        return ret;
    }

    std::string GetResult()
    {
        std::string ret;
        
        if (exitcode <= Unknown)
        {
            ret += "run the task fail, reason: ";
            switch (exitcode)
            {
                case DevideZero:
                    ret += "DevideZero";
                    break;
                case ModZero:
                    ret += "ModZero";
                    break;
                case Unknown:
                    ret += "Unknown";
                    break;
                default:
                    break;
            }
        }
        else
        {
            ret += "run the task success, result: ";
            ret += std::to_string(a);
            ret += " ";
            ret += op_;
            ret += " ";
            ret += std::to_string(b);
            ret += " ";
            ret += "= ";
            ret += std::to_string(answer);
        }

        return ret;
    }

    ~Task()
    {}

private:
    int a;
    int b;
    char op_;

    int answer = 0;
    ErrorCode exitcode = Normal;
};